import Link from "next/link"; import type { Metadata } from "next"; import { notFound } from "next/navigation"; import { EventRow } from "@/components/event-row"; import { LiveFeed } from "@/components/live-feed"; import { Badge, Bar, Chip, Empty, PageHeader, Panel, Stat, Table, Td, TierBadge } from "@/components/ui"; import { api } from "@/lib/api"; import { feedHref, fmtInt, relTime, typeLabel } from "@/lib/format"; export const dynamic = "force-dynamic"; /** Section order and labels for the desk (spec §104). Unknown categories are appended in API order. */ const SECTIONS: { key: string; label: string }[] = [ { key: "government", label: "Government" }, { key: "finance", label: "Business & markets" }, { key: "infrastructure", label: "Infrastructure" }, { key: "health", label: "Health" }, { key: "news", label: "Media" }, { key: "cyber", label: "Cyber" }, { key: "ai", label: "AI" }, { key: "science", label: "Science" }, ]; export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise { const { slug } = await params; const d = await api.country(slug); if (!d) return { title: "Country not found" }; return { title: `${d.country.name} desk`, description: `Government, business, infrastructure, health, media, cyber, AI and science signals from ${d.country.name}, detected live by WebSensor.`, alternates: { canonical: `/country/${slug}` } }; } export default async function CountryPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; const d = await api.country(slug); if (!d) notFound(); const code = d.country.code; const name = d.country.name; const events24 = d.sources.reduce((n, s) => n + (s.events_24h ?? 0), 0); const ordered = [...SECTIONS.map((s) => ({ ...s, items: d.by_category.find((c) => c.category === s.key)?.items ?? [] })), ...d.by_category.filter((c) => !SECTIONS.some((s) => s.key === c.category)).map((c) => ({ key: c.category, label: c.category, items: c.items }))]; const maxType = Math.max(1, ...d.by_type.map((t) => t.n)); const firstParty = d.sources.filter((s) => s.first_party !== false).length; return ( <> Countries / {code}} title={{d.country.flag} {name}} description={`Official government, business, infrastructure, health and media signals from ${name}, grouped by desk. Sources are the organizations' own channels; media reports are marked EXTERNAL.`} actions={Live feed →} />
Major events · 24 h} dense action={live →}> {d.breaking.length ? d.breaking.map((e) => ) : No breaking signal from {name} in the last 24 h.}
{ordered.map((s) => ( live →}> {s.items.length ? s.items.map((e) => ) : No {s.label.toLowerCase()} signal from {name} recently.} ))}
filter sources →}> {d.sources.length === 0 ? ( No source is attributed to {name} yet. ) : ( {d.sources.map((s) => ( ))}
{s.name} {s.domain} {s.first_party === false ? : }
{s.categories.slice(0, 3).map((c) => {c})}
{s.sensor_count ?? 0} {fmtInt(s.events_24h ?? 0)} {s.last_event_at ? relTime(s.last_event_at) : "—"}
)}
); }